<?php
namespace app\shop\model;
use app\BaseModel;
use think\facade\Db;
use app\shop\model\AdminShopSpePrice;



class IndexUserCollage extends BaseModel
{
    //定义表名
    protected $name = 'longbing_card_shop_user_collage';

    /**
     * @var array
     * 查询器
     */
    protected $append = [
        'spe_text'
    ];
    /**
     * @param $value
     * @param $data
     * @return mixed
     * get spename
     */
    public function getSpeTextAttr($value,$data){
        $spe_model = new AdminShopSpePrice();
        $spe_data  = $spe_model->singeSpePrice(['id'=>$data['spe_price_id']]);
        return $spe_data;

    }

    /**
     * @param $dis
     * @param int $page
     * @return mixed
     * 获取商品拼团列表
     */
    public function collageList($dis,$page = 10){
        $data = $this
            ->alias('a')
            ->leftJoin('longbing_card_shop_collage_list b' ,'a.collage_id = b.id')
            ->leftJoin('longbing_card_goods c' ,'b.goods_id = c.id')
            ->leftJoin('longbing_card_shop_collage d' ,'b.collage_id = d.id')
            ->leftJoin('longbing_card_shop_collage d' ,'b.collage_id = d.id')
            ->where($dis)
            ->field(['a.*,a.id as collage_id' ,'b.id as goods_id,b.cover as goods_cover,b.name as goodsname'])
            ->order('a.id desc')
            ->paginate($page)
            ->toArray();
        return $data;
    }

    /**
     * @param $dis
     * @param $data
     * @return IndexShopCollageList
     * 编辑拼团信息
     */

    public function collageUpdate($dis,$data){
        $data['update_time'] = time();
        $res = $this->where($dis)->update($data);
        return $res;

    }

    /**
     * @param $dis
     * @param $data
     * @return IndexShopCollageList
     * 添加拼团信息
     */

    public function collageAdd($data){
        $data['update_time'] = time();
        $data['create_time'] = time();
        $res = $this->insert($data);
        return $res;

    }


    /**
     * @param $dis
     * @return bool
     * @throws \Exception
     * 删除拼团信息
     */

    public function collageDel($dis){
        $res = $this->where($dis)->delete();
        return $res;
    }










}